package meth

import (
	"fmt"
	"net"
)

func filterBySubnet(original []ARPEntry, cidr string) (map[string]ARPEntry, error) {
	_, subnet, err := net.ParseCIDR(cidr)
	if err != nil {
		return nil, fmt.Errorf("无效的子网格式: %w", err)
	}

	filtered := make(map[string]ARPEntry)
	for _, entry := range original {
		ip := net.ParseIP(entry.IP)
		if ip != nil && subnet.Contains(ip) {
			filtered[entry.IP] = entry
		}
	}
	return filtered, nil
}
